package com.xd.source;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.xd.source.adapter.ViewPageAdapter;
import com.xd.source.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

public class MessageFragment extends BaseFragment {


    private List<Fragment> mFragmentList;
    List<View> views;
    List<String> titles;
    private ViewPager mViewPager;
    private TabLayout tab_layout;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Log.e("Fragment", "初始化消息");
        View view = inflater.inflate(R.layout.fragment_message, null, false);
        mViewPager = view.findViewById(R.id.view_pager);
        tab_layout = view.findViewById(R.id.tab_layout);

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        titles = new ArrayList<>();
        titles.add("消息");
        titles.add("联系人");
        mFragmentList = new ArrayList<>();
        mFragmentList.add(new ConversationFragment());
        mFragmentList.add(new ContactFragment());
        ViewPageAdapter adapter = new ViewPageAdapter(views, titles);
        for (String title : titles) {
            tab_layout.addTab(tab_layout.newTab().setText(title));
        }
        tab_layout.setupWithViewPager(mViewPager);
        mViewPager.setAdapter(adapter);
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.e("Fragment", "恢复消息");
    }
}
